package com.teaching.dao;

import java.util.ArrayList;
import java.util.List;

import com.teaching.entity.Teacher;

public class TeacherDAO {
	private List<Teacher> teacherList=new ArrayList<Teacher>();

	public boolean addTeacher(Teacher teacher) {
		System.out.println("Teacher DAO: add teacher");
		return teacherList.add(teacher);
	}

	// 查找对应课程和年级的老师，将匹配成功的老师放入一个list，然后返回。
	public List<Teacher> getTeachers(Integer grade, Integer course) {
		System.out.println("Teacher DAO: get teachers by grade and course");
		
		List<Teacher> courseTeachers=new ArrayList<Teacher>();
		
		for (Teacher teachers : teacherList) { 
			if(teachers.findByCourse(course, grade)) {
				System.out.println(teachers.toString());
				courseTeachers.add(teachers);
			}
			
			
		}
		return courseTeachers;
	}
	
	public boolean Have(Integer teacherID) {
		System.out.println("Teacher DAO: have teacher");
		for (Teacher teachers : teacherList) { 
			if(teachers.getTeacherID()==teacherID) {
				return true;
			}
		}
		return false;
	}
	
	public boolean ModifyTeacher(Teacher teacher) {
		System.out.println("Teacher DAO: modify teacher");
		for (Teacher teachers : teacherList) { 
			if(teachers.getTeacherID()==teacher.getTeacherID()) {
				teachers.setAddress(teacher.getAddress());
				teachers.setAge(teacher.getAge());
				teachers.setCourse(teacher.getCourse());
				teachers.setFee(teacher.getFee());
				teachers.setGender(teacher.getGender());
				teachers.setGrade(teacher.getGrade());
				teachers.setName(teacher.getName());
				teachers.setUniversity(teacher.getUniversity());
				return true;
			}
		}
		return false;
	}
	
	public List<Teacher> getTeacherList() {
		return teacherList;
	}

	public void setTeacherList(List<Teacher> teacherList) {
		this.teacherList = teacherList;
	}
	
	
	
	
	

}
